import 'package:flutter/material.dart';
import 'package:landlore/consts.dart';
import 'package:flutter/cupertino.dart';

class YearMonthCupPicker extends StatelessWidget {
  YearMonthCupPicker(
      {super.key,
      required this.callback,
      required this.inputYear,
      required this.inputMonth});

  final int inputYear;
  final int inputMonth;

  final Function callback;

  @override
  Widget build(BuildContext context) {
    String? selectedValueSum;
    int selectedYear =inputYear;
    int selectedMonth=inputMonth;
    int yearIndex = Consts().getYearIndex(inputYear);
    int monthIndex =Consts().getMonthIndex(inputMonth );

    return Row(
      children: [
        //年选择器
        Expanded(
          flex: 1,
          child: CupertinoPicker(
            scrollController:
                FixedExtentScrollController(initialItem: yearIndex),
            // backgroundColor: Colors.white,
            // looping: true,
            itemExtent: 60,
            onSelectedItemChanged: (index) {
              selectedYear = Consts().getYearByIndex(index);
              selectedValueSum = "$selectedYear.$selectedMonth月";
              callback(selectedValueSum, selectedYear,selectedMonth);
            },
            children: Consts.yearList,
          ),
        ),
        //月选择器
        Expanded(
          flex: 1,
          child: CupertinoPicker(
            scrollController:
                FixedExtentScrollController(initialItem: monthIndex),
            // backgroundColor: Colors.white,
            // looping: true,
            itemExtent: 60,
            onSelectedItemChanged: (index) {
              selectedMonth = Consts().getMonthByIndex(index);
              selectedValueSum = "$selectedYear.$selectedMonth月";
              callback(selectedValueSum,selectedYear,selectedMonth);
            },
            children: Consts.monthList,
          ),
        ),
      ],
    );
  }
}
